package base.day16.dao;

import base.day16.domain.Student;

import java.util.ArrayList;

public class OtherStudentDao implements BaseOtherStudentDao{
    //创建学生对象数组
    static ArrayList<Student> stus=new  ArrayList<Student>();
    static  {
        Student stu=new Student("001","张三",20,"1999-11-11");
        Student stu2=new Student("002","李四",30,"1999-11-11");
        stus.add(stu);
        stus.add(stu2);
    }

    public  void deldteStudentById(String deid) {
        int index=getIndex(deid);
        stus.remove(index);
    }
    public  int getIndex(String id){
        int index=-1;
        for (int i = 0; i < stus.size(); i++) {
            Student stu=stus.get(i);
            if (stu!=null&&stu.getId().equals(id)){
                index=i;
                break;
            }
        }
        return index;
    }

    public boolean addStudent(Student stu) {
       stus.add(stu);
       return true;
    }

    public Student[] findAllStudent() {
        Student[] stu=new Student[stus.size()];
        for (int i = 0; i < stus.size(); i++) {
            stu[i]=stus.get(i);
        }
        return stu;
    }

    public void studentDao(String upateId, Student newstu) {
        int index = getIndex(upateId);
        stus.set(index,newstu);
    }
}
